<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="layout/template.xhtml">

<ui:define name="body">

<a:loadScript src="js/jquery.maskedinput-1.3.js" />
<a:loadScript src="js/jquery.maskedinput-1.1.4.pack.js" />


    <h:form id="PesquisaClienteForm">

        <rich:panel>
            <f:facet name="header">Consulta Cliente</f:facet>
            
            
           <s:decorate id="sexoField" template="layout/edit.xhtml">
            <ui:define name="label">Pessoa</ui:define>
            <h:selectOneRadio id="sexo" value="#{VendaBean.tipoPessoa}" required="true">
            <a:support event="onchange" reRender="cpfCnpj" />  
            
			  <f:selectItem itemLabel="Fisica" itemValue="FISICA"/>
			  <f:selectItem itemLabel="Juridica" itemValue="JURIDICA"/>
			</h:selectOneRadio>
           </s:decorate>            

			<s:div id="cpfCnpj">
				<a:region rendered="#{VendaBean.tipoPessoa eq 'FISICA' }" >
		            <s:decorate id="cpfField" template="/layout/edit.xhtml"  >
               		<ui:define name="label">CPF</ui:define>
		                <h:inputText id="cpfFieldId" value="#{VendaBean.cpf}" size="18" maxlength="14"  >
							<rich:jQuery selector="#cpfFieldId" query="mask('999.999.999-99')" timing="onload"></rich:jQuery>
							<s:validate />
		                </h:inputText>
		            </s:decorate>
				</a:region>	  
				       
				<a:region rendered="#{VendaBean.tipoPessoa eq 'JURIDICA' }" >
		            <s:decorate id="cnpjField" template="/layout/edit.xhtml"  >
                		<ui:define name="label">CNPJ</ui:define>
		                <h:inputText id="cnpj" value="#{VendaBean.cnpj}"  maxlength="21" size="22"   >
		                	<rich:jQuery selector="#cnpj" query="mask('99.999.999/9999-99')" timing="onload"></rich:jQuery>
							<s:validate />
		                </h:inputText>
		            </s:decorate>
				</a:region>	 
								   
			</s:div>
            
            <div style="clear:both"/>

	        <div class="actionButtons">
	            <a:commandButton id="btPesquisaCliente" value="Consultar"
	                    action="#{VendaBean.pesquisaCliente}" reRender="resultPnl" />
	        </div>

        </rich:panel>
        
        <rich:panel id="resultPnl">
            <f:facet name="header">Cliente Selecionado</f:facet>
            
			<h:messages />		
			
			<s:decorate id="cnpjField2" template="/layout/edit.xhtml" rendered="#{not empty VendaBean.clientePJ}" >
                <ui:define name="label">CNPJ</ui:define>
                <h:outputText id="cnpjFieldId2"  value="#{VendaBean.clientePJ.cnpj}"  />
            </s:decorate>	
            
			<s:decorate id="razaoSocialField2" template="/layout/edit.xhtml" rendered="#{not empty VendaBean.clientePJ}" >
                <ui:define name="label">Razao Social</ui:define>
                <h:outputText id="razaoSocialFieldId2"  value="#{VendaBean.clientePJ.razaoSocial}"  />
            </s:decorate>	   
                     
			<s:decorate id="fone1Field2" template="/layout/edit.xhtml" rendered="#{not empty VendaBean.clientePJ}" >
                <ui:define name="label">Fone (1)</ui:define>
                <h:outputText id="fone1FieldId2"  value="#{VendaBean.clientePJ.fone1}"  />
            </s:decorate>	            

            <s:decorate id="cpfField2" template="/layout/edit.xhtml" rendered="#{not empty VendaBean.clientePF}" >
                <ui:define name="label">CPF</ui:define>
                <h:outputText id="cpfFieldId2"  value="#{VendaBean.clientePF.cpf}"  />
            </s:decorate>
            
            <s:decorate id="nomeField2" template="/layout/edit.xhtml" rendered="#{not empty VendaBean.clientePF}" >
                <ui:define name="label">Nome</ui:define>
                <h:outputText id="nomeFieldId2"  value="#{VendaBean.clientePF.nome}"  />
            </s:decorate>
            
            <s:decorate id="fon1Field2" template="/layout/edit.xhtml" rendered="#{not empty VendaBean.clientePF}" >
                <ui:define name="label">Fone (1)</ui:define>
                <h:outputText id="fone1FieldId2"  value="#{VendaBean.clientePF.fone1}"  />
            </s:decorate>
            
            <div style="clear:both"/>
            
	        <div class="actionButtons">
	            <a:commandButton id="btAddClientePF" value="Adicionar" rendered="#{not empty VendaBean.clientePF}"
	                    action="#{VendaBean.addClientePF()}"  reRender="painelListaClientesPF"/>
	            <a:commandButton id="btAddClientePJ" value="Adicionar" rendered="#{not empty VendaBean.clientePJ}"
	                    action="#{VendaBean.addClientePJ()}"  reRender="painelListaClientesPJ"/>

	        </div>
	        	        	        

        </rich:panel>
        
			<rich:panel id="painelListaClientesPF">
				<f:facet name="header">Cliente(s) PF - Selecionado(s)</f:facet>


				<div class="dialog"><h:outputText
					value="Não existe registro."
					rendered="#{empty VendaBean.venda.clientesPF}" />
					
					<rich:dataTable id="clientesPFSelecionadosList" value="#{VendaBean.venda.clientesPF}"
					var="_clientesPFSelecionado" rendered="#{not empty VendaBean.venda.clientesPF}" styleClass="dr-table-cell-center-text" >
					
					<h:column>
						<f:facet name="header">cpf</f:facet>
                    	#{_clientesPFSelecionado.cpf}
					</h:column>
					
					<h:column>
						<f:facet name="header">nome</f:facet>
                    	#{_clientesPFSelecionado.nome}
					</h:column>

	                <h:column>
	                    <f:facet name="header">Remove</f:facet>
	                    <a:commandLink id="linkRemovePF"
	                         value="Remove"
	                         action="#{VendaBean.removeClientePF(_clientesPFSelecionado)}" reRender="painelListaClientesPF"/>
	                </h:column>
					
				</rich:dataTable></div>
				
				<div style="clear: both" />

			</rich:panel>
			
			<rich:panel id="painelListaClientesPJ">
				<f:facet name="header">Cliente(s) PJ - Selecionado(s)</f:facet>


				<div class="dialog"><h:outputText
					value="Não existe registro."
					rendered="#{empty VendaBean.venda.clientesPJ}" />
					
					<rich:dataTable id="clientesPJSelecionadosList" value="#{VendaBean.venda.clientesPJ}"
					var="_clientesPJSelecionado" rendered="#{not empty VendaBean.venda.clientesPJ}" styleClass="dr-table-cell-center-text" >
					
					<h:column>
						<f:facet name="header">cnpj</f:facet>
                    	#{_clientesPJSelecionado.cnpj}
					</h:column>
					
					<h:column>
						<f:facet name="header">Razao Social</f:facet>
                    	#{_clientesPJSelecionado.razaoSocial}
					</h:column>
					
	                <h:column>
	                    <f:facet name="header">Remove</f:facet>
	                    <a:commandLink id="linkRemovePJ"
	                         value="Remove"
	                         action="#{VendaBean.removeClientePJ(_clientesPJSelecionado)}" reRender="painelListaClientesPJ"/>
	                </h:column>
					
				</rich:dataTable></div>
				
				<div style="clear: both" />

			</rich:panel>        
        
        <div class="actionButtons">

    		<s:button id="btLote" value="Lote" view="/vendaLote.xhtml" propagation="join" />


        </div>


        <div class="actionButtons">
        </div>
    </h:form>

</ui:define>

</ui:composition>
